﻿using Abp.DynamicEntityProperties;
using Abp.DynamicEntityProperties.Extensions;
using Abp.UI.Inputs;
using AbpProjectTemplate.Application.Shared.Dtos;
using AbpProjectTemplate.Domain.Users;
using System;
using System.Globalization;
using System.Threading.Tasks;

namespace AbpProjectTemplate.Application.Shared
{
    public class TestAppService : ApplicationService
    {
        public IDynamicPropertyManager DynamicPropertyManager { get; set; }
        public IDynamicPropertyValueManager DynamicPropertyValueManager { get; set; }
        public IDynamicEntityPropertyManager DynamicEntityPropertyManager { get; set; }
        public IDynamicEntityPropertyValueManager DynamicEntityPropertyValueManager { get; set; }

        public async Task DynamicEntityPropertyTest(string name)
        {
            var cityProperty = new DynamicProperty
            {
                PropertyName = name,//Property name. 
                InputType = InputTypeBase.GetName<SingleLineStringInputType>(),
                //Permission = "App.Permission.DynamicProperty.City",
                TenantId = AbpSession.TenantId
            };

            //

            await this.DynamicPropertyManager.AddAsync(cityProperty);

            var property = await this.DynamicEntityPropertyManager.AddAsync<User, long>(cityProperty, 1);

            var valueOfRow1 = new DynamicEntityPropertyValue(property, entityId: "1", value: "Istanbul", tenantId: AbpSession.TenantId);


            await this.DynamicEntityPropertyValueManager.AddAsync(valueOfRow1);

            this.DynamicEntityPropertyValueManager.GetValues<User, long>("1");
        }

        public CultureInfo GetCurrentCulture()
        {
            return CultureInfo.CurrentCulture;
        }
    }
}
